/*
 * Copyright [2013-2021], Alibaba Group Holding Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.polardbx.net.packet;

import com.alibaba.polardbx.net.compress.IPacketOutputProxy;
import com.alibaba.polardbx.net.util.BufferUtil;

/**
 * Created by simiao.zw on 2014/8/4.
 */
public class BinaryResultSetHeaderPacket extends MySQLPacket {

    public int column_count;

    @Override
    protected String packetInfo() {
        return "Binary ResultSet header packet";
    }

    public IPacketOutputProxy write(IPacketOutputProxy proxy) {
        proxy.packetBegin();
        int size = getPacketLength();
        proxy.checkWriteCapacity(proxy.getConnection().getPacketHeaderSize() + size);

        proxy.writeUB3(size);
        proxy.write(packetId);

        proxy.writeLength(column_count);
        proxy.packetEnd();
        return proxy;
    }

    private int getPacketLength() {
        int size = BufferUtil.getLength(column_count);
        return size;
    }
}
